/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.imagelettericon;

import com.github.akashohos90.imageletter.drawable.RoundedDrawable;
import com.github.akashohos90.imageletter.drawable.TextDrawable;
import com.imagelettericon.util.PixelMapUtils;
import com.imagelettericon.util.TextUtils;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.media.image.PixelMap;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * 单元测试
 *
 * @since 2021-06-08
 */
public class ExampleOhosTest {
    private static final int VALUE_TWO = 2;
    /**
     * 包名测试
     */
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.imagelettericon", actualBundleName);
    }

    /**
     * 获取PixelMap测试
     */
    @Test
    public void testPixelMapFromResource() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext();
        PixelMap pixelMap = PixelMapUtils.getPixelMapFromResource(context, ResourceTable.Media_one);
        assertNotNull(pixelMap);
    }

    /**
     * 字符截取测试
     */
    @Test
    public void testComputeText() {
        String text = TextUtils.computeText("Alane Bast", VALUE_TWO);
        assertEquals("AB", text);
    }

    /**
     * 资源图片转换背景测试
     */
    @Test
    public void testRoundedDrawable() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext();
        PixelMap pixelMap = PixelMapUtils.getPixelMapFromResource(context, ResourceTable.Media_one);
        RoundedDrawable.IBuilder imageDrawableBuilder = RoundedDrawable.builder().rect();
        RoundedDrawable roundedDrawable = imageDrawableBuilder.build(pixelMap);
        assertNotNull(roundedDrawable);
    }

    /**
     * 字符转换背景测试
     */
    @Test
    public void testTextDrawable() {
        TextDrawable.IBuilder textDrawableBuilder = TextDrawable.builder().rect();
        TextDrawable textDrawable = textDrawableBuilder.build("Alane Bast", Color.getIntColor("#ffffff"));
        assertNotNull(textDrawable);
    }
}